package uia.alumni.data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;



/**
 *
 * @author Even Åby Larsen (even.larsen@uia.no)
 */
@Entity
public class UserRole {
    @Id @Column(name="USERID", insertable=false, updatable=false)
    private int uid;

    @Id
    private String roleName;

    @ManyToOne
    @JoinColumn(name="USERID")
    private User user;
    

    public UserRole(User user, String roleName) {
        this.user = user;
        this.roleName = roleName;
    }

    /** Entities must have default constructor */
    public UserRole() {
        // nothing to do
    }

    
    public String getRoleName() {
        return roleName;
    }


    public boolean equals(Object that) {
        if (that instanceof UserRole)
            return roleName.equals(((UserRole)that).roleName);
        else
            return false;
    }


    public String toString() {
        return user.getUserName()+"-"+roleName;
    }

    public final static long serialVersionUID = 1;

}
